﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace thinger.VisionModels
{    
   
    public class IEC_Timer_TON
    {
        public IEC_Timer_TON(long PT)
        {
            this.PT = PT;
        }


        private Stopwatch sw = new Stopwatch();

        //设定时间
        public long PT { get; set; }


        private bool input;
        /// <summary>
        /// 输入
        /// </summary>
        public bool Input
        {
            get { return input; }
            set
            {
                input = value;
                if (input)
                {
                    sw.Start();
                }
                else
                {
                    sw.Stop();
                    sw.Reset();
                }

            }
        }

        private bool output;
        /// <summary>
        /// 输出
        /// </summary>
        public bool Output
        {
            get
            {
                output = sw.ElapsedMilliseconds > PT;
                if (output)
                {
                    sw.Stop();
                }
                return output;
            }
        }


        /// <summary>
        /// 当前运行的时间
        /// </summary>
        public long ET
        {
            get
            {
                if (output)
                {
                    return PT;
                }
                else
                {
                    return sw.ElapsedMilliseconds;
                }
            }
        }


        /// <summary>
        /// 定时器的状态
        /// </summary>
        public bool IsRunning
        {
            get { return sw.IsRunning; }
        }


    }
}
